package com.hulizuofang.wol.chat.client.ui.event.sendmessage;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HasHandlers;
import com.hulizuofang.wol.chat.client.data.ChatUser;

public class SendMessageEvent extends GwtEvent<SendMessageHandler> {
	private static final Type<SendMessageHandler> TYPE = new Type<SendMessageHandler>();
	private final ChatUser recipient;
	private final String message;

	SendMessageEvent(ChatUser recipient, String message) {
		this.recipient = recipient;
		this.message = message;
	}
	
	public ChatUser getRecipient() {
		return recipient;
	}
	
	public String getMessage() {
		return message;
	}

	public static void fire(final HasHandlers source, ChatUser sender, String message) {
		source.fireEvent(new SendMessageEvent(sender, message));
	}

	public static Type<SendMessageHandler> getType() {
		return TYPE;
	}
	@Override
	public Type<SendMessageHandler> getAssociatedType() {
		return getType();
	}

	@Override
	protected void dispatch(SendMessageHandler handler) {
		handler.onSend(this);
	}

}
